﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TCM.Controllers
{
    public class EmployeeController : Controller
    {
        private TCMContext db = new TCMContext();

        //
        // GET: /Employee/

        public ActionResult Index()
        {
            return View(db.EMPLOYEEBASEs.ToList());
        }

        //
        // GET: /Employee/Details/5

        public ActionResult Details(Guid? id = null)
        {
            EMPLOYEEBASE employeebase = db.EMPLOYEEBASEs.Find(id);
            if (employeebase == null)
            {
                return HttpNotFound();
            }
            return View(employeebase);
        }

        //
        // GET: /Employee/Create

        public ActionResult Create()
        {
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs
                .Where<MAPSTRINGBASE>
                (x => x.ATTRIBUTENAME.Equals("statusid") &&
                    x.ENTITYNAME.Equals("EMPLOYEEBASE")).ToList().AsEnumerable(), "MAPSTRINGID", "DISPLAYNAME");
            return View();
        }

        //
        // POST: /Employee/Create

        [HttpPost]
        public ActionResult Create(EMPLOYEEBASE employeebase)
        {
            if (ModelState.IsValid)
            {
                employeebase.EMPLOYEEID = Guid.NewGuid();
                db.EMPLOYEEBASEs.Add(employeebase);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs
                .Where<MAPSTRINGBASE>
                (x => x.ATTRIBUTENAME.Equals("statusid") &&
                    x.ENTITYNAME.Equals("EMPLOYEEBASE")).ToList().AsEnumerable(), "MAPSTRINGID", "DISPLAYNAME");
            return View(employeebase);
        }

        //
        // GET: /Employee/Edit/5

        public ActionResult Edit(Guid? id = null)
        {
            EMPLOYEEBASE employeebase = db.EMPLOYEEBASEs.Find(id);
            if (employeebase == null)
            {
                return HttpNotFound();
            }
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs
                .Where<MAPSTRINGBASE>
                (x => x.ATTRIBUTENAME.Equals("statusid") &&
                    x.ENTITYNAME.Equals("EMPLOYEEBASE")).ToList().AsEnumerable(), "MAPSTRINGID", "DISPLAYNAME", employeebase.STATUSID);
            return View(employeebase);
        }

        //
        // POST: /Employee/Edit/5

        [HttpPost]
        public ActionResult Edit(EMPLOYEEBASE employeebase)
        {
            if (ModelState.IsValid)
            {
                db.Entry(employeebase).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs
                .Where<MAPSTRINGBASE>
                (x => x.ATTRIBUTENAME.Equals("statusid") &&
                    x.ENTITYNAME.Equals("EMPLOYEEBASE")).ToList().AsEnumerable(), "MAPSTRINGID", "DISPLAYNAME", employeebase.STATUSID);
            return View(employeebase);
        }

        //
        // GET: /Employee/Delete/5

        public ActionResult Delete(Guid? id = null)
        {
            EMPLOYEEBASE employeebase = db.EMPLOYEEBASEs.Find(id);
            if (employeebase == null)
            {
                return HttpNotFound();
            }
            return View(employeebase);
        }

        //
        // POST: /Employee/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(Guid id)
        {
            EMPLOYEEBASE employeebase = db.EMPLOYEEBASEs.Find(id);
            db.EMPLOYEEBASEs.Remove(employeebase);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}